home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++,ualberta.cmput.201
- Subject: Re: class/function pointer help!
- Date: 30 Mar 1996 23:46:42 GMT
- Organization: Netcom
- Message-ID: <4jkh52$i4b@dfw-ixnews6.ix.netcom.com>
- References: <4jhlk7$1eke@pulp.ucs.ualberta.ca>
- NNTP-Posting-Host: den-co15-25.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Sat Mar 30 5:46:42 PM CST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <4jhlk7$1eke@pulp.ucs.ualberta.ca>, ryangall@gpu.srv.ualberta.ca
- says...
- >
- >Hi, I have a class that uses a function pointer. The problem Im having is
- >that the pointer doesnt want to access the function when the function is a
- >local function to the calling class. Here is what I mean....
- >
- >class expression
- > {
- > public:
- > string S;
- > list L;
- > int initlist();
- > int isexpr(int);
- > };
- >
- >
- >list, and string are both classes.
- >
- >char * string::POP( int (* separator)(int c) );
- >
- >this works when I define isexpr(int) globally, but I want to beable to
- >call function expression::isexpr(int).....when I do this...
- >
- > while((temp=S.POP( isexpr )))
- > {
- >
- > the compiler say:" member function must be called or its address taken."
- >
- >how do I declare the member function as a function pointer?!
-
- First things first. Member functions are not the same as functions and are
- interchangeable under no circumstances (although you can get away with it if
- they are static). The reason is that member functions have an implciit "this"
- argument, and the mechanism for passing that argument is undefined. It makes
- no sense to call a member function by pointer unless you have an object to
- call it with.
-
- You *can* use a pointer-to-member-function, but you also have to supply the
- object to invoke it on....
-
- john lilley
-
-
-
-